package com.shiwaixiangcun.customer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.entity.RecordBean;
import com.shiwaixiangcun.customer.utils.TimerToTimerUtil;

import java.util.List;


/**
 * <<<<<<< HEAD:app/src/main/java/com/shiwaixiangcun/customer/adapter/RecordfinishListAdapter.java
 * =======
 * <p>
 * <p>
 * >>>>>>> 1.3.0:app/src/main/java/com/shiwaixiangcun/customer/adapter/RecordFinishListAdapter.java
 *
 * @author Administrator
 * @date 2016/7/13
 */
public class RecordFinishListAdapter extends BaseAdapter {
    private List<RecordBean.DataBean.ElementsBean> list;
    private Context context;

    public RecordFinishListAdapter(List<RecordBean.DataBean.ElementsBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_finish_access, null);
            mViewHolder = new ViewHolder();
            mViewHolder.tvFinishContent = convertView.findViewById(R.id.tv_finish_content);
            mViewHolder.tvFinishTime = convertView.findViewById(R.id.tv_finish_time);

            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        mViewHolder.tvFinishContent.setText(list.get(position).getContent());


        String s = TimerToTimerUtil.stampToDate(list.get(position).getCreateTime() + "");

        mViewHolder.tvFinishTime.setText(s);
        boolean judgeToday = TimerToTimerUtil.getJudgetoDay(s);
        boolean judgeYesterday = TimerToTimerUtil.getJudgeYesterday(s);
        if (judgeToday) {
            mViewHolder.tvFinishTime.setText(TimerToTimerUtil.stampToNewDate(list.get(position).getCreateTime() + ""));
        } else if (judgeYesterday) {
            mViewHolder.tvFinishTime.setText(TimerToTimerUtil.stamYesterDate(list.get(position).getCreateTime() + ""));
        }

        return convertView;
    }

    static class ViewHolder {
        TextView tvFinishContent;
        TextView tvFinishTime;
    }

}
